package cn.guozeyiblog.netutils;

import java.io.IOException;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

import cn.guozeyiblog.blogutils.ArticleDetail;

public class XMLUtils {
	public static List<ArticleDetail> GetArticleList(String result) throws XmlPullParserException, IOException{
		ArrayList<ArticleDetail> list = new ArrayList<>();
		XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
		factory.setNamespaceAware(true);
		XmlPullParser xpp = factory.newPullParser();
		xpp.setInput( new StringReader (result) );
		int eventType = xpp.getEventType();
		while (eventType != XmlPullParser.END_DOCUMENT) {
			if(eventType == XmlPullParser.START_DOCUMENT) {
				System.out.println("Start document");
			} else if(eventType == XmlPullParser.START_TAG) {
				System.out.println("Start tag "+xpp.getName());
			} else if(eventType == XmlPullParser.END_TAG) {
				System.out.println("End tag "+xpp.getName());
			} else if(eventType == XmlPullParser.TEXT) {
				System.out.println("Text "+xpp.getText());
			}
			eventType = xpp.next();
		}
		System.out.println("End document");



		return list;
	}
}
